package com.example.demo.controller.voj;

import com.example.demo.common.IdParam;
import com.example.demo.dto.ProblemCategoryDto;
import com.example.demo.dto.ResponseDto;
import com.example.demo.param.voj.VojCategorySaveParam;
import com.example.demo.service.ProblemService;
import com.example.demo.service.VojProblemCategoriesService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * 题库模块-试题分类
 */
@Controller
@RequestMapping("/category")
public class ProblemCategoryController {

    private static final Logger log = LoggerFactory.getLogger(ProblemCategoryController.class);
    @Resource
    private VojProblemCategoriesService vojProblemCategoriesService;

    /**
     * 查询试题分类.
     * @return
     */
    @RequestMapping("/list")
    @ResponseBody
    public ResponseDto<List<ProblemCategoryDto>> list() {
        List<ProblemCategoryDto> data = vojProblemCategoriesService.getAll();
        ResponseDto result = new ResponseDto().buildSucceed();
        result.setContent(data);
        return result;
    }

    /**
     * 创建/编辑试题分类.
     * @return
     */
    @RequestMapping(value="/save", method= RequestMethod.POST)
    @ResponseBody
    public ResponseDto save(@RequestBody VojCategorySaveParam param) {
        vojProblemCategoriesService.save(param);
        ResponseDto responseDto = new ResponseDto<>().buildSucceed();
        return responseDto;
    }


    /**
     * 删除试题分类.
     * @return
     */
    @RequestMapping(value="/delete", method=RequestMethod.POST)
    @ResponseBody
    public ResponseDto delete(@RequestBody IdParam param) {
        vojProblemCategoriesService.delete(param.getId());
        ResponseDto responseDto = new ResponseDto<>().buildSucceed();
        return responseDto;
    }
}
